import axios from 'axios';
import store from '@/store'
import { getToken } from '@/utils/auth'

const service = axios.create({
    baseURL: process.env.VUE_APP_API, 
    timeout: 5000 // 超时时间
})

// request拦截器
service.interceptors.request.use(config => {
    if (store.getters.token) {
        config.headers['X-Token'] = getToken() 
    }
    return config
  }, error => {
    console.log(error)
    return Promise.reject(error)
})
  
export default service

